﻿using DomainService.IService.Sys;
using DomainService.Service.Sys;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model.BusinessModel.InPut;
using Model.BusinessModel.OutPut;
using Model.BusinessModel.OutPut.sys;
using Model.DomainModel.Sys;
using Utility;
using Utility.Enum;

namespace OverallAuth_WebApi.Controllers.Sys
{
    /// <summary>
    /// 公司模块
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    [ApiExplorerSettings(GroupName = nameof(ModeuleGroupEnum.SysCorporation))]
    public class SysCorporationController : BaseController
    {
        #region 构造实列化

        /// <summary>
        /// 公司服务
        /// </summary>
        public ISysCorporationService _sysCorporationService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sysCorporationService"></param>
        public SysCorporationController(ISysCorporationService sysCorporationService)
        {
            _sysCorporationService = sysCorporationService;
        }

        #endregion

        #region 接口

        /// <summary>
        /// 获取所有公司数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<SysCorporationOutPut> GetAllCorporation()
        {
            ReceiveStatus<SysCorporationOutPut> receiveStatus = new();
            var list = _sysCorporationService.GetAllCorporation(GetLoginUserMsg().CorporationKey);
            receiveStatus.data = list;
            return receiveStatus;
        }

        /// <summary>
        /// 获取所有公司数据,select结构
        /// </summary>
        /// <returns>以select结构，返回所有公司</returns>
        [HttpGet]
        public ReceiveStatus<SelectOutPut> GetAll()
        {
            ReceiveStatus<SelectOutPut> receiveStatus = new();
            var list = _sysCorporationService.GetAll(GetLoginUserMsg().CorporationKey);
            receiveStatus.data = list;
            return receiveStatus;
        }

        /// <summary>
        ///  获取公司下的系统--未用接口
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<TreeOutPut> GetCorporationSystemList()
        {
            ReceiveStatus<TreeOutPut> receiveStatus = new();
            var list = _sysCorporationService.GetCorporationSystemList();
            receiveStatus.data = list;
            return receiveStatus;

        }

        /// <summary>
        /// 新增公司
        /// </summary>
        /// <param name="sysCorporation">公司数据</param>
        [HttpPost]
        public ReceiveStatus Insert(SysCorporation sysCorporation)
        {
            sysCorporation.CreateTime = DateTime.Now;
            sysCorporation.CreateUser = GetLoginUserMsg().UserId;
            return _sysCorporationService.Insert(sysCorporation);

        }

        /// <summary>
        /// 修改公司
        /// </summary>
        /// <param name="sysCorporation">公司数据</param>
        [HttpPost]
        public ReceiveStatus Update(SysCorporation sysCorporation)
        {
            return _sysCorporationService.Update(sysCorporation);
        }

        /// <summary>
        /// 设置公司是否启用
        /// </summary>
        /// <param name="updateCorporationIsOpenInPut">修改模型</param>
        [HttpPost]
        public ReceiveStatus SetCorporationIsOpen(UpdateIsOpenInPut updateCorporationIsOpenInPut)
        {
            return _sysCorporationService.SetCorporationIsOpen(updateCorporationIsOpenInPut);
        }
        #endregion
    }
}
